package com.alibaba.citrus.ots.price.ability.functions.entity.activity;

import com.alibaba.citrus.ots.common.util.SpringContextUtil;
import com.alibaba.citrus.ots.price.repository.ActivityQueryRepository;
import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.otsforecastsales.domian.activitytermgiftrelation.model.ActivityTermGiftRelation;
import com.epoch.app.otsplatformenhance.model.dto.QueryCustomerSelectRequest;
import com.epoch.app.otspricecenter.model.dto.ActivityGiftItemRelationSDO;
import com.epoch.app.otspricecenter.sdo.ActivityTermGiftRelationSDO;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hanguo
 * @date 2021/11/10
 * @Description 赠品实体
 */
@Data
public class ActivityTermGiftRelationEntity {

    private static Log log = Log.getLogger(ActivityTermGiftRelationEntity.class);

    /**
     * 活动查询资源库
     */
    private static ActivityQueryRepository queryRepository = SpringContextUtil.getBean(ActivityQueryRepository.class);


    private ActivityGiftItemRelationSDO activityGiftItemRelationSDO;

    public static ActivityTermGiftRelationEntity of(ActivityGiftItemRelationSDO activityGiftItemRelationSDO){
        ActivityTermGiftRelationEntity activityTermGiftRelationEntity = new ActivityTermGiftRelationEntity();
        activityTermGiftRelationEntity.setActivityGiftItemRelationSDO(activityGiftItemRelationSDO);
        return activityTermGiftRelationEntity;
    }

    public List<ActivityTermGiftRelationSDO> queryActivityIdAndTermIdList(){
        List<ActivityTermGiftRelation> activityTermGiftRelations = queryRepository.queryActivityIdAndTermIdList(this.activityGiftItemRelationSDO);
        if(CollectionUtils.isNotEmpty(activityTermGiftRelations)){
           return activityTermGiftRelations.stream().map(item->{
                ActivityTermGiftRelationSDO activityTermGiftRelationSDO = new ActivityTermGiftRelationSDO();
                BeanUtils.copyProperties(item,activityTermGiftRelationSDO);
                return activityTermGiftRelationSDO;
            }).collect(Collectors.toSet()).stream().collect(Collectors.toList());
        }

        return new ArrayList<>();
    }
}
